home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java for 3D & VRML Worlds
/
Java for 3d and VRML Worlds.iso
/
vs
/
browser
/
cpb10eb.exe
/
DATA.Z
/
tv.java
< prev
next >
Wrap
Text File
|
1996-09-26
|
8KB
|
284 lines
/*-----------------------------------------------------------------------------
* Copyright(C) 1996 Sony Corporation. All rights reserved.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Sony Corporation;
* the contents of this file is not to be disclosed to third parties, copied
* or duplicated in any form, in whole or in part, without the prior written
* permission of Sony Corporation.
*
* File: tv.java
* Auther: sugino
*----------------------------------------------------------------------------*/
import vrml.*;
import vrml.field.*;
import vrml.node.*;
public class tv extends Script {
/* propertys */
/*************************/
/* channels/volume array */
/*************************/
SFFloat channels[] = new SFFloat[3]; /* channelp number shapes */
SFFloat volumes[] = new SFFloat[10]; /* volume indicater shapes */
SFColor powerBtn; /* power button */
SFFloat chs[] = new SFFloat[3]; /* monitor faces */
int MaxVolume ; /* volume max */
int MaxChannel; /* channel max */
int volume ; /* sound volume (0-9) */
int channel ; /* channel no(0-2) */
boolean powerOn ; /* true the power is on */
int ignoreTimer ;
SFBool tglTm ;
SFTime bgm1Start ;
SFTime bgm1Stop ;
SFTime kachiStart ;
SFFloat bgmVol ;
/*************************************************
* constructor
*************************************************/
public void initialize() {
tglTm = (SFBool)getEventOut("tglTm");
bgm1Start = (SFTime) getEventOut("bgm1Start");
bgm1Stop = (SFTime) getEventOut("bgm1Stop");
kachiStart = (SFTime) getEventOut("kachiStart");
bgmVol = (SFFloat) getEventOut("bgmVol");
MaxVolume =10; /* volume max */
MaxChannel=3 ; /* channel max */
volume = 8 ; /* sound volume (0-9) */
channel = 0; /* channel no(0-2) */
powerOn = false;/* true the power is on */
/* ---------------------------------------------
* initialize
* ------------------------------------------- */
/* reference to Channnel shapes */
channels[0] = (SFFloat)getEventOut("ch1Shape");
channels[1] = (SFFloat)getEventOut("ch2Shape");
channels[2] = (SFFloat)getEventOut("ch3Shape");
chs[0] = (SFFloat)getEventOut("ch1");
chs[1] = (SFFloat)getEventOut("ch2");
chs[2] = (SFFloat)getEventOut("ch3");
/* reference to vol indicater shapes */
volumes[0] = (SFFloat)getEventOut("vol1Shape");
volumes[1] = (SFFloat)getEventOut("vol2Shape");
volumes[2] = (SFFloat)getEventOut("vol3Shape");
volumes[3] = (SFFloat)getEventOut("vol4Shape");
volumes[4] = (SFFloat)getEventOut("vol5Shape");
volumes[5] = (SFFloat)getEventOut("vol6Shape");
volumes[6] = (SFFloat)getEventOut("vol7Shape");
volumes[7] = (SFFloat)getEventOut("vol8Shape");
volumes[8] = (SFFloat)getEventOut("vol9Shape");
volumes[9] = (SFFloat)getEventOut("vol10Shape");
/* reference to Power buttn shapes */
powerBtn = (SFColor)getEventOut("powerShape");
bgmVol.setValue((float)volume*0.1f);
}
public void processEvent(Event e) {
String name = e.getName();
ConstField v = (ConstField)e.getValue();
double t = e.getTimeStamp();
if (name.equals("volDown")){
volDown ((ConstSFBool)v, t) ;
}
else if (name.equals("volUp")) {
volUp ((ConstSFBool)v, t) ;
}
else if (name.equals("chUp")){
chUp ((ConstSFBool)v, t) ;
}
else if (name.equals("chDown")){
chDown ((ConstSFBool)v, t) ;
}
else if(name.equals("tglPower")){
tglPower ((ConstSFBool)v, t) ;
}
else if (name.equals("turnOffInfo")){
turnOffInfo ((ConstSFTime)v, t) ;
}
}
/*************************************************
* script methods
*************************************************/
public void volDown (ConstSFBool b, double t){
if(!powerOn) return ;
if(b.getValue()){return;}
/* System.out.println("volDown"); */
volume--;
setVolume(volume);
showInfo();
/* TODO Ä└ì█é╔ë╣é≡âZâbâgé╖éΘ */
bgmVol.setValue((float)volume*0.1f);
}
public void volUp (ConstSFBool b, double t){
if(!powerOn) return ;
if(b.getValue()){return;}
/* System.out.println("volUp"); */
volume++;
setVolume(volume);
showInfo();
bgmVol.setValue((float)volume*0.1f);
/* TODO Ä└ì█é╔ë╣é≡âZâbâgé╖éΘ */
}
public void chUp (ConstSFBool b, double t){
if(!powerOn) return ;
if(b.getValue()){return;}
/* System.out.println("chUp"); */
channel++;
setChannel(channel);
playTv();
showInfo();
}
public void chDown (ConstSFBool b, double t){
if(!powerOn) return ;
if(b.getValue()){return;}
/* System.out.println("chDown"); */
channel--;
setChannel(channel);
playTv();
showInfo();
}
public void tglPower (ConstSFBool b, double t){
if(b.getValue()){return;}
float f[] = new float[3];
f[0]=f[1]=f[2]=0.0f;
if(powerOn) {
/* turn Off power */
powerOn = false ;
f[0]=1.0f;
clearTv();
clearInfo();
bgm1Stop.setValue(t);
}
else {
powerOn = true ;
f[1]=1.0f;
playTv();
showInfo();
bgm1Start.setValue(t);
}
powerBtn.setValue(f);
/* System.out.println("tglPower" + ff[0] + " " +
ff[1] + " " + ff[2] ); */
kachiStart.setValue(t + 1);
}
public void turnOffInfo (ConstSFTime time, double t){
if(0<ignoreTimer){
ignoreTimer--;
return ;
}
tglTm.setValue(false);
clearInfo();
clearVolume();
}
void clearInfo(){
clearChannel();
clearVolume();
}
/*************************************************
* showInfo()
*************************************************/
void showInfo(){
setChannel(channel);
setVolume(volume);
ignoreTimer = 1;
tglTm.setValue(true);
}
/*************************************************
* Clear TV
*************************************************/
void clearTv(){
for (int i=0;i<MaxChannel;i++){
chs[i].setValue(1.0f);
}
}
/*************************************************
* playTv
*************************************************/
void playTv(){
clearTv();
chs[channel].setValue(0.0f);
}
/*************************************************
* Clear Channel shape
*************************************************/
void clearChannel(){
for (int i=0;i<MaxChannel;i++){
channels[i].setValue(1.0f);
}
}
/*************************************************
* set volume shape
*************************************************/
void setChannel(int ch){
if(ch<0){ch =MaxChannel-1;}
if(ch>=MaxChannel){ch=0;}
channel = ch ;
clearChannel();
channels[ch].setValue(0.0f);
}
/*************************************************
* Clear Volume shape
*************************************************/
void clearVolume(){
for(int i=0;i<MaxVolume;i++){
/* disable volume */
volumes[i].setValue(1.0f);
}
}
/*************************************************
* set volume shape
*************************************************/
void setVolume(int vol){
if(vol<0){vol =0;}
if(vol>MaxVolume){vol=MaxVolume;}
volume = vol ;
clearVolume();
for(int i=0;i<vol;i++){
volumes[i].setValue(0.0f);
}
}
}